import java.util.Collections;
import java.util.List;

public class ViewTask {

	public ViewTask() {

	}
	/**
	 * This method is called to execute the view command
	 * @param userInputElements
	 * @param tasksInTempStorage
	 * @param tasksOnDisplay
	 */
	public void execute(UserInputElements userInputElements, List<Task> tasksInTempStorage, List<Task> tasksOnDisplay) {
		String message;
		String viewParameter = userInputElements.getTaskDescription().toLowerCase();
		/*
		if(typeTasksOnDisplay.equalsIgnoreCase("/ALL/"))  {
			viewParameter = "all";
		}
		else if(typeTasksOnDisplay.equalsIgnoreCase("/STAR/")) {
			viewParameter = "star";
		}
		else if(typeTasksOnDisplay.equalsIgnoreCase("/DEADLINE/")) {
			viewParameter = "deadline";
		}
		else if(typeTasksOnDisplay.equalsIgnoreCase("/FINISHED/")) {
			viewParameter = "finished";
		}
		else {
			;
		}
		 */
		if (viewParameter.equals("")) {
			message = "no parameter provided for view";
			TaskO.taskOMainScreen.appendOutput(message);
			System.out.println(message);
		}

		// TODO 1 - how do i get all
		else if (!((viewParameter.equals("all"))
				|| (viewParameter.equals("star"))
				|| (viewParameter.equals("deadline"))
				|| (viewParameter.equals("finished")))) {
			message = "incorrect or misspelled parameter inputted";
			TaskO.taskOMainScreen.appendOutput(message);
			System.out.println(message);
		}

		else {
			this.clearCurrentTasksOnDisplay(tasksOnDisplay);
			this.viewFromTempStorage(viewParameter, tasksInTempStorage,
					tasksOnDisplay);
		}
	}

	/**
	 * 
	 * @param tasksOnDisplay
	 */
	//TODO 2, later reference
	private void clearCurrentTasksOnDisplay(List<Task> tasksOnDisplay) {
		try {
			tasksOnDisplay.clear();
		} catch (Exception e) {
			TaskO.taskOMainScreen.appendOutput("the tasks on display may be shown incorrectly");
		}
	}

	/**
	 * 
	 * @param viewParameter
	 * @param tasksInTempStorage
	 * @param tasksOnDisplay
	 */
	public void viewFromTempStorage(String viewParameter,
			List<Task> tasksInTempStorage, List<Task> tasksOnDisplay) {
		if(viewParameter == "all") {
			for(int i=0; i<tasksInTempStorage.size(); i++) {
				tasksOnDisplay.add(tasksInTempStorage.get(i));	
			}
		}
		//TODO 3: not done tasks

		else if(viewParameter == "star") {
			for (int i = 0; i < tasksInTempStorage.size(); i++) {
				if(tasksInTempStorage.get(i).getIsTaskStarred()) {
					tasksOnDisplay.add(tasksInTempStorage.get(i));
				}
			}
		}

		else if(viewParameter == "deadline") {
			for (int i = 0; i < tasksInTempStorage.size(); i++) {
				if(tasksInTempStorage.get(i).getTaskType().name().equalsIgnoreCase("DEADLINETASK")) {
					tasksOnDisplay.add(tasksInTempStorage.get(i));
				}
			}
		}

		else if(viewParameter == "finished") {
			for (int i = 0; i < tasksInTempStorage.size(); i++) {
				if(tasksInTempStorage.get(i).getIsTaskDone()) {
					tasksOnDisplay.add(tasksInTempStorage.get(i));
				}	
			}
		}
		else ;
	}
}
